import mysql.connector
from Tools.read_config import ReadConfig
from Tools import get_path
class DoMysql:
    def do_mysql(self,query_sql,state='all'):#query_sql-->查询语句，state----all 多条 1是1条
        #读取配置文件中的数据库信息
        db_config = eval(ReadConfig().get_config(get_path.case_config_path,'DB_MYSQL','db_config'))
        #创建连接
        db_connect =mysql.connector.connect(**db_config)

        #游标cursor
        cursor = db_connect.cursor()


        #执行语句
        cursor.execute(query_sql)
        #读取结果，打印
        res = cursor.fetchone() #针对多行数据结果，输出数据类型列表嵌套元组
        # print(res)
        # print(int(res[0]+1))#结果+1

        # # #关闭游标
        # cursor.close()
        # #
        # # #关闭连接
        # db_connect.close()

        return res


if __name__ == '__main__':
    # sql语句
    query_sql = "SELECT * FROM user where user_id"
    res=DoMysql().do_mysql(query_sql)
    print(res[1])